package com.smh.genericity;

/**
 * @description: 泛型苹果
 * @author: shenmhk
 * @create: 2020-10-21 10:56
 */
public class Apple<T> {

    //使用T类型定义变量
    private T info;

    //下面方法使用T类型定义构造器
    public Apple(T info){
        this.info = info;
    }
    public Apple(){

    }

    public T getInfo(){
        return info;
    }

    public void setInfo(T info){
        this.info = info;
    }

    public static void main(String[] args){
        //由于传给T形参的是String，所有构造器参数只能是String
        Apple<String> apple1 = new Apple<String>("苹果");//调用有参构造器
        System.out.println(apple1.getInfo());

        //由于传给T形参的是Double，所有构造器参数只能是Double
        Apple<Double> apple2 = new Apple<Double>();//调用无参构造器
        apple2.setInfo(5.560);
        System.out.println(apple2.getInfo());
    }

}
